package com.tg.app.activity.device;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.appbase.custom.config.ApiUrl;
import com.base.BaseActivity;
import com.magicindicator.buildins.UIUtil;
import com.tange.base.toolkit.StringUtils;
import com.tg.app.R;
import com.tg.app.activity.CloudServiceActivity;
import com.tg.app.helper.ActivityHelper;
import com.tg.app.helper.DeviceHelper;
import com.tg.appcommon.android.TGToast;
import com.tg.data.bean.DeviceSettingsInfo;
import com.tg.data.helper.DeviceTypeHelper;

public class Buy4GServiceReminderActivity extends BaseActivity {

    private static final String KYE_DEVICE_ID = "KYE_DEVICE_ID";

    private long deviceId = 0;
    private String mUUID = "";
    private String mDeviceType = DeviceTypeHelper.DEVICE_SIM;

    public static void launch(Context context, long deviceId, String type, String uuid) {
        Intent intent = new Intent();
        intent.putExtra(KYE_DEVICE_ID, deviceId);
        if (!StringUtils.isEmpty(type)){
            intent.putExtra(ApiUrl.DEVICE_TYPE, type);
        }

        if (!StringUtils.isEmpty(uuid) && uuid.length() == 12){
            intent.putExtra(ApiUrl.DEVICE_UUID, uuid);
        }

        intent.setClass(context, Buy4GServiceReminderActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_service_buy_reminder);
        deviceId = getIntent().getLongExtra(KYE_DEVICE_ID, 0);
        mDeviceType = getIntent().getStringExtra(ApiUrl.DEVICE_TYPE);
        mUUID = getIntent().getStringExtra(ApiUrl.DEVICE_UUID);
        initView();
        hideActionBar();
    }

    @Override
    public boolean shouldSetStatusBarColor() {
        return true;
    }

    protected void initView() {
        TextView tvTitle = findViewById(R.id.device_name);
        tvTitle.setText("");
        modifyToolBar();

        ImageView closeIv = findViewById(R.id.back_toolbar);
        closeIv.setImageResource(R.drawable.ic_tange_global_icon_close_dark_gray);

        closeIv.setOnClickListener(v -> finish());


        findViewById(R.id.buy).setOnClickListener(v -> {
            if (DeviceTypeHelper.isCar(mDeviceType)){
                ActivityHelper.openCarService(Buy4GServiceReminderActivity.this, deviceId, this.mUUID);
            }else{
//                Intent intent = new Intent();
//                DeviceSettingsInfo info = new DeviceSettingsInfo();
//                info.deviceID = deviceId;
//                intent.putExtra(DeviceSettingsActivity.EXT_DEVICE_INFO, info);
//                intent.putExtra(CloudServiceActivity.EXT_CLOUD_SERVICE_TYPE, CloudServiceActivity.EXT_CLOUD_SERVICE_TYPE_SIM);
//                intent.setClass(Buy4GServiceReminderActivity.this, CloudServiceActivity.class);
//                startActivity(intent);
//                finish();

                TGToast.showToast("该功能暂未开放");
            }


        });

        findViewById(R.id.later).setOnClickListener(v -> {
            finish();
        });

        TextView tipsTv = findViewById(R.id.tips_1);
        View bottomView = findViewById(R.id.bottom_container);

        // (屏幕高度 - 底部白色高度) / 3.0 的位置
        tipsTv.post(() -> {
            final int targetMarginTop = (int) ((UIUtil.getScreenHeight(this) - bottomView.getMeasuredHeight()) * 1.0 / 3.0);
            RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) tipsTv.getLayoutParams();
            lp.topMargin = targetMarginTop;
            tipsTv.setLayoutParams(lp);
        });
    }
}
